from django.db import models
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.models import CoreModel, SoftDeleteModel
from dvadmin.utils.viewset import CustomModelViewSet
from rest_framework.viewsets import ModelViewSet

# drf专用过滤器模块
from django_filters import rest_framework as filters


class Cailiao(CoreModel):

    cai_liao = models.TextField(verbose_name="材料", blank=True, null=True)
    cai_liao_ming_cheng = models.TextField(verbose_name="材料名称", blank=True, null=True)
    liao_hou = models.TextField(verbose_name="料厚", blank=True, null=True)
    qu_fu_qiang_du = models.TextField(verbose_name="屈服强度", blank=True, null=True)
    la_shen_qiang_du = models.TextField(verbose_name="拉伸强度", blank=True, null=True)
    shi_fou_re_cheng_xing = models.TextField(verbose_name="是否热成型", blank=True, null=True)

    class Meta:
        db_table = 'station_weldspot_cailiao'


class CailiaoModelSerializer(CustomModelSerializer):    
    class Meta:
        model = Cailiao
        fields = '__all__'


class CailiaoFilter(filters.FilterSet):
    cai_liao = filters.CharFilter(field_name='cai_liao', lookup_expr='icontains')
    cai_liao_ming_cheng = filters.CharFilter(field_name='cai_liao_ming_cheng', lookup_expr='icontains')
    liao_hou = filters.CharFilter(field_name='liao_hou', lookup_expr='icontains')
    qu_fu_qiang_du = filters.CharFilter(field_name='qu_fu_qiang_du', lookup_expr='icontains')
    class Meta:
        models = Cailiao
        fields = '__all__'


class CailiaoViewSet(CustomModelViewSet):
    values_queryset= Cailiao.objects.all()
    serializer_class = CailiaoModelSerializer
    filter_class = CailiaoFilter